import re


def filter_string(input_string, filter_word):
    """
    从输入字符串中过滤掉指定的单词

    :param input_string: 原始字符串
    :param filter_word: 要过滤掉的单词
    :return: 过滤后的字符串
    """
    return input_string.replace(filter_word, "")


print(filter_string("this is a day ", "day"))


def filter_sensitive_words(text, sensitive_words_list):
    """
    使用正则表达式过滤掉文本中的敏感词

    :param text: 要进行过滤的原始文本
    :param sensitive_words_list: 预设的敏感词列表
    :return: 过滤后的文本
    """
    for word in sensitive_words_list:
        pattern = re.compile(r'\b' + re.escape(word) + r'\b')
        text = re.sub(pattern, '', text)

    return text.strip()

print(filter_sensitive_words("this is a day ", ["this", "day"]))

import os

# 获取当前脚本所在的目录路径
script_dir = os.path.dirname(os.path.abspath(__file__))
absolute_path = ('敏感词汇表.txt')

# 获取相对路径
file_path = os.path.join(script_dir,absolute_path)

print(file_path)

def read_and_split_txt(file_path):
    """
    读取txt文件内容并按逗号分割后返回列表

    :param file_path: txt文件的路径
    :return: 按逗号分割后的内容列表
    """
    with open(file_path, 'r') as file:
        content = file.read()
        split_content = content.split(',')
        return [item.strip() for item in split_content]
    
print(read_and_split_txt(file_path))